﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace shopform
{
    public partial class ProjectMenu : Form
    {
        private Project myProj;

        /// <summary>
        /// ProjectMenu constructor
        /// </summary>
        public ProjectMenu()
        {
            InitializeComponent();
            selectProject();
            loadProjectDataIntoLabels();
        }

        private void selectProject()
        {
            try
            {
                String selectedProject;
                ProjectChooserForm aProjectChooserForm = new ProjectChooserForm();
                aProjectChooserForm.ShowDialog();
                selectedProject = aProjectChooserForm.getSelectedProjectID();
                aProjectChooserForm.Dispose();

                if (selectedProject == null)
                {
                    this.Close();
                }

                this.LabelProjIDValue.Text = selectedProject;
                this.myProj = new Project(selectedProject);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba\n" + ex.Message);
            }
        }

        /// <summary>
        /// Loads labels with project data.
        /// </summary>
        private void loadProjectDataIntoLabels()
        {
            Company myComp = new Company(this.myProj.CompanyID);
            this.LabelCompanyValue.Text = myComp.CompanyName;
            this.LabelCountryValue.Text = myComp.CompanyCountry;
            this.LabelProjAddrValue.Text = myProj.ProjectAddr;
            this.LabelProjCityValue.Text = myProj.ProjectCity;
            this.LabelProjIDValue.Text = myProj.ProjectID;
            this.LabelProjectNameValue.Text = myProj.ProjectName;
            this.LabelProjDateValue.Text = myProj.DateCreated.Replace("0:00:00", "");
        }

        private void ButtonCloseWindow_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ButtonGenerateContract_Click(object sender, EventArgs e)
        {
            try
            {
                HTMLCreator contractGen = new ContractGenerator(this.myProj);
                contractGen.writeOutputFile();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Hiba:" + exc.Message);
            }
        }
    }
}
